package jee.boot.common.utils;

import org.springframework.core.env.Environment;

/**
 * 读取yml中的变量
 */
public class SpringEnvironmentHolder {
    private Environment environment;

    /**
     * 根据yml中配置的
     * @param key
     * @return
     */
    public static String getValue(String key) {
        try {
            Environment environment = getEnvironment();
            String property = environment.getProperty(key);
            return property;
        }catch (Exception e){
            return null;
        }

    }

    private static Environment getEnvironment() {
        return SpringContextHolder.getApplicationContext().getBean(Environment.class);
    }
}
